{include file='common/head'}
<!--员工发布&#45;&#45;说天喊地-->
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">
    <blockquote class="layui-elem-quote layui-text">
        <div class="demoTable layui-form">
            <!--<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>-->
            <div class="demoTable layui-form">
                <div class="layui-input-inline">
                    <select name="type" lay-verify="required" lay-search lay-filter="bank_id">
                        <option value="">请选择消息类型</option>
                        <option value="1">客服消息</option>
                        <option value="2">系统消息</option>
                        <option value="3">订单消息</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input type="text" id="start_time" name="start_time" autocomplete="off" placeholder="选择发送开始时间" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <input type="text" id="end_time" name="end_time" autocomplete="off" placeholder="选择发送结束时间" class="layui-input">
                </div>
                <button class="layui-btn " data-type="reload" ><i class="layui-icon">&#xe615;</i>搜索</button>
                <button class="layui-btn addInfo">添加</button>
            </div>
        </div>
    </blockquote>
    <div class="demoTable layui-for">
        <table class="layui-table" lay-data="{height: 'full-150', url:'{:url('News/massageList')}',edit:true, page:true, id:'testReload',loading:true}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80,fixed: true,templet:'#id'}">编号</th>
                <th lay-data="{field:'title', width:200,templet: '#title'}">消息标题</th>
                <th lay-data="{field:'content', width:200,templet: '#content'}">消息内容</th>
                <th lay-data="{field:'type', width:200,templet: '#type'}">消息类别</th>
                <th lay-data="{field:'user_name', width:200,templet: '#user_name'}">发送用户</th>
                <th lay-data="{field:'note_time', width:200,templet: '#note_time'}">通知时间</th>
                <th lay-data="{field:'add_time', width:200,templet: '#add_time'}">添加时间</th>
                <th lay-data="{field:'update_time',width:200,templet: '#update_time'}">修改时间</th>
                <th lay-data="{fixed: '', width:200,fixed: 'right', align:'left', toolbar: '#barDemo'}">操作</th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a title="编辑" lay-event="edit" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe642;</i></a>
            <a title="删除" lay-event="del" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe640;</i></a>
        </script>
        <script type="text/html" id="id" lay-event="detail_content">
            <span>{{ d.id }}</span>
        </script>
        <script type="text/html" id="user_name" lay-event="detail_content">
            <span>{{ d.user_name }}</span>
        </script>
        <script type="text/html" id="add_time" lay-event="detail_content">
            <span>{{ d.add_time }}</span>
        </script>
        <script type="text/html" id="update_time" lay-event="detail_content">
            <span>{{ d.update_time }}</span>
        </script>
        <script type="text/html" id="content" lay-event="detail_content">
            <span>{{ d.content }}</span>
        </script>
    </div>
    {include file='common/footer'}
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form;
            var $ = layui.$, active = {
                reload: function(){
                    var type = $('select[name="type"] option:checked').val();
                    var start_time = $('input[name="start_time"]').val();
                    var end_time = $('input[name="end_time"]').val();
                    //执行重载
                    table.reload('testReload', {
                        where: {
                            type:type,
                            start_time:start_time,
                            end_time:end_time
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //监听表格复选框选择
            table.on('checkbox(demo)', function(obj){
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        title: '编辑',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['100%', '100%'],
                        content: '{:url("News/massageModifyPage")}?id='+data.id,
                        end: function () {
                            table.reload('testReload');
                        },
                    });
                }else if(obj.event === 'del'){
                    layer.confirm('确定删除么', function(index){
                        $.ajax({
                            url:'{:url("News/delMassage")}?id='+data.id,
                            type:'get',
                            dataType:'json',
                            success:function(val){
                                if(val.code ==200){
                                    obj.del();
                                    layer.close(index);
                                }
                                if(val.code==500){
                                    layer.msg(val.msg);
                                }
                            }
                        });

                    });
                }
            });

            $('.addInfo').on('click',function(){
                layer.open({
                    type: 2,
                    title: '添加',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['100%', '100%'],
                    content: '{:url("News/massageModifyPage")}',
                    end: function () {
                        table.reload('testReload');
                    },
                });
            });
        });
    </script>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            var endDate= laydate.render({
                elem: '#end_time',//选择器结束时间
                type: 'datetime',
                min:"1970-1-1",//设置min默认最小值
                done: function(value,date){
                    startDate.config.max={
                        year:date.year,
                        month:date.month-1,//关键
                        date: date.date,
                        hours: 0,
                        minutes: 0,
                        seconds : 0
                    }
                }
            });
            //日期范围
            var startDate=laydate.render({
                elem: '#start_time',
                type: 'datetime',
                max:"2099-12-31",//设置一个默认最大值
                done: function(value, date){
                    endDate.config.min ={
                        year:date.year,
                        month:date.month-1, //关键
                        date: date.date,
                        hours: 0,
                        minutes: 0,
                        seconds : 0
                    };
                }
            });

        });
    </script>
    </body>
    </html>